class CreateTags < ActiveRecord::Migration
  def self.up
    create_table :tags do |t|
      t.string :name, :null => false

      t.references :wallet
    end

    add_index :tags, [:wallet_id, :name], :unique => true

    create_table :operations_tags, :id => false do |t|
      t.references :tag
      t.references :operation
    end

    add_index :operations_tags, [:tag_id, :operation_id], :unique => true
  end

  def self.down
    drop_table :tags
    drop_table :operations_tags
#    drop_table :operations_tags
  end
end
